/****************************************
 * Copyright (c) 2015 NiuWa.
 * All rights reserved.
 * Created on 2015年4月13日
 * 
 * Contributors:
 * 	   bwz - initial implementation
 ****************************************/
package com.niuwa.p2p.service.impl.business;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.niuwa.p2p.core.mvc.entity.PageBean;
import com.niuwa.p2p.core.utils.DictUtil;
import com.niuwa.p2p.dao.business.LoanClaimDao;
import com.niuwa.p2p.dao.business.RepayPlanDao;
import com.niuwa.p2p.entity.PageQuery;
import com.niuwa.p2p.entity.business.RepayPlan;
import com.niuwa.p2p.service.business.RepayPlanService;
import com.niuwa.p2p.vo.front.account.RefundOrSettleBalanceVo;
import com.niuwa.p2p.vo.front.account.TransferDetailVo;


/**
 * @title RepayPlanServiceImpl.java
 *
 * @author bwz
 * @version 1.0
 * @created 2015年4月13日
 */
@Service
public class RepayPlanServiceImpl implements RepayPlanService {
	
	@Autowired
	private RepayPlanDao repayPlanDao;
	
	
	@Override
	public List<RepayPlan> selectRepayPlanListPage(Map<String, Object> paramMap) throws Exception {
		List<RepayPlan> list = repayPlanDao.selectRepayPlanListPage(paramMap);
		return list;
	}

	
	@Override
	public TransferDetailVo selectRepayplanBaseInfo(Map<String, Object> paramMap) throws Exception {
		TransferDetailVo baseInfoVo = repayPlanDao.selectRepayplanBaseInfo(paramMap);
		return baseInfoVo;
	}

	
	@Override
	public RefundOrSettleBalanceVo getRefundInfo(Map<String, Object> paramMap) throws Exception {
		RefundOrSettleBalanceVo rosbVo = repayPlanDao.getRefundInfo(paramMap);
		return rosbVo;
	}


	@Override
	public RefundOrSettleBalanceVo getSettleBalanceInfo(Map<String, Object> paramMap) throws Exception {
		RefundOrSettleBalanceVo rosbVo = repayPlanDao.getSettleBalanceInfo(paramMap);
		return rosbVo;
	}

	
	@Override
	public RepayPlan refund(Map<String, Object> paramMap) throws Exception {
		// TODO 还款
		return null;
	}

	
	@Override
	public boolean settleBalance(Map<String, Object> paramMap) throws Exception {
		// TODO 结清
		return false;
	}
	@SuppressWarnings("unused")
	@Override
	public PageBean<RepayPlan> selectRepayPlanPageListByParams(
			Map<String, Object> paramMap){
		String dictType = "REPAY_STATUS";
		assert paramMap.get(PageQuery.PAGEQUERY) != null;
		List<RepayPlan> repayPlanlist =  repayPlanDao.selectRepayPlanListByParams(paramMap);
		for(RepayPlan repayPlan:repayPlanlist){
			String repayStatus = repayPlan.getRepayStatus();
			String repayStatusName = DictUtil.getDictNameByTypeAndCode(dictType, repayStatus);
			repayPlan.setRepayStatusName(repayStatusName);
		}
		if(repayPlanlist==null) repayPlanlist=new ArrayList<RepayPlan>();
		int totalCount = repayPlanDao.countp2pRepayPlanByParams(paramMap);
		PageBean<RepayPlan> page = new PageBean<RepayPlan>(totalCount);
		// 设置当前页
		page.setPage(((PageQuery) paramMap.get(PageQuery.PAGEQUERY)).getPage());
		page.setRows(repayPlanlist);
		return page;
	}
}
